package org.hzy.actions;

import java.io.IOException;
import java.io.PrintWriter;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.hzy.entity.TUser;
import org.hzy.services.IUserLoginService;
import org.hzy.tools.JsonUtil;
import org.hzy.tools.PageBean;
import org.hzy.vos.MyUser;

import com.opensymphony.xwork2.ActionContext;

public class LoginAction {
	private MyUser mu;
	private IUserLoginService iu;
	public MyUser getMu() {
		return mu;
	}
	public void setMu(MyUser mu) {
		this.mu = mu;
	}
	public IUserLoginService getIu(){
		return iu;
	}
	public void setIu(IUserLoginService iu) {
		this.iu = iu;
	}
	@Action(value="login1",className="LogAction",results={@Result(name="success",location="/htmls/My.jsp",type="dispatcher"),
			@Result(name="error",location="/Page/error.jsp",type="dispatcher")})
	public String login() throws IOException{
		System.out.println(mu.getUname()+"login!!!!!!!!!!! ");
		TUser tu=iu.getUserByName(mu.getUname(),mu.getUpwd());
		PrintWriter out=ServletActionContext.getResponse().getWriter();
		if(tu!=null){
			System.out.println(tu.getUname());
			return "success";
		}
		return "error";
	}
	
	
	@Action(value="show",className="LogAction",results={@Result(name="success",location="/htmls/show.jsp",type="dispatcher"),
			@Result(name="error",location="/Page/error.jsp",type="dispatcher")})
	public String show() throws IOException{
		System.out.println("show!!!!!!!!!!! ");
		PrintWriter out=ServletActionContext.getResponse().getWriter();
		ActionContext ctx=ActionContext.getContext();
		Integer start=Integer.valueOf(ServletActionContext.getRequest().getParameter("start"));
		Integer limit=Integer.valueOf(ServletActionContext.getRequest().getParameter("limit"));
		PageBean page=iu.getPageBean(start, limit);
		System.out.println(JsonUtil.PageJson(page));
		out.print(JsonUtil.PageJson(page));
		return null;
	}
	
}
